import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import xj.toolkit.util.PackageUtils;

/**
 * @PlugInUnitCfg.java  COPYRIGHT xiaojian
 * 
 * Created on 2019年7月12日 下午4:51:37
 */

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class PlugInUnitCfg {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		File jarFile = new File("D:\\xiaojian-source\\xt-toolkit\\itc-plugin-demo\\plugin\\demo.jar");
		URLClassLoader cls = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}, Thread.currentThread().getContextClassLoader());
		Thread.currentThread().setContextClassLoader(cls);
		String[] resources = PackageUtils.getResourceInPackage("plugin-unit-cfg");
		
		for (String str : resources) {
			if (str.endsWith("cfg")) {
				int dotBegin = str.indexOf(".");
				String packageName = str.substring(0, dotBegin);
				String unitsName = str.substring(dotBegin + 1);
				InputStream in = cls.getResourceAsStream(packageName + "/" + unitsName);
				
				File out = new File("D:\\" + unitsName);
				FileUtils.writeLines(out, IOUtils.readLines(in));
			}
			
		}
	}

}
